import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import * as dotenv from 'dotenv';
import * as joi from 'joi';
import { TypeOrmModule } from '@nestjs/typeorm';
import { join } from 'path';
import { UserModule } from './user/user.module';
import { LogsModule } from './logs/logs.module';
// import Configuration from './configuration';
import { connectionParams } from '../ormconfig';

const envFilePath = `.env.${process.env.NODE_ENV || 'development'}`;

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath,
      load: [() => dotenv.config({ path: '.env' })],
      validationSchema: joi.object({
        DB_PORT: joi.number().valid(3306, 3308).default(3306),
        NODE_ENV: joi
          .string()
          .valid('development', 'production')
          .default('development'),
        DB_URL: joi.string().domain(),
        // DB_HOST: joi.string().ip(),
        DB_HOST: joi
          .alternatives()
          .try(joi.string().ip(), joi.string().domain()),
      }),
    }),
    /* ConfigModule.forRoot({
      isGlobal: true,
      load: [Configuration],
    }), */
    TypeOrmModule.forRoot(connectionParams),
    UserModule,
    LogsModule,
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

// https://github.com/surmon-china/nodepress  mongodb
